
#include <iostream>
using namespace std;

typedef struct BiNode {
  char data;
  struct BiNode *lchild, *rchild;
} BiTNode, *BiTree;

void CreateBiTree(BiTree &T) {
  char ch;
  cin >> ch;
  if (ch == '#')
    T = NULL;
  else {
    T = new BiTNode;
    T->data = ch;
    CreateBiTree(T->lchild);
    CreateBiTree(T->rchild);
  }
}

int node = 0;

void PrintNode(BiTree &T) {
  if (T) {
    if (!T->lchild && !T->rchild) {
      cout << T->data;
      node++;
    }
    PrintNode(T->lchild);
    PrintNode(T->rchild);
  }
}

int main() {
  BiTree tree;
  CreateBiTree(tree);
  PrintNode(tree);
  cout << endl << node;
}
